package com.yb.guigu.pick.code.generator.config;

import com.yb.guigu.pick.core.constant.RabbitMQConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Copyright (C), 2022-2023, 姚兵
 * Author: 32210
 * Date: 2023/6/11 20:45
 * FileName: RabbitMQConfig
 * Description:
 */

@Configuration
public class RabbitMQConfig {

    @Configuration
    public static class EmailQueueConfig{

        @Bean
        Queue emailQueue(){
            return QueueBuilder.durable(RabbitMQConstant.EmailQueueConstant.QUEUE)
                .deadLetterExchange(RabbitMQConstant.DeadLetterQueueConstant.EXCHANGE)
                .deadLetterRoutingKey(RabbitMQConstant.DeadLetterQueueConstant.ROUTING_KEY)
                .build();
        }

        @Bean
        Exchange emailExchange(){
            return ExchangeBuilder.directExchange(RabbitMQConstant.EmailQueueConstant.EXCHANGE).durable(true).build();
        }

        @Bean
        Binding emailBinder(){
            return BindingBuilder.bind(emailQueue()).to(emailExchange()).with(RabbitMQConstant.EmailQueueConstant.ROUTING_KEY).noargs();
        }
    }

    @Configuration
    public static class MobileQueueConfig{

        @Bean
        Queue mobileQueue(){
            return QueueBuilder.durable(RabbitMQConstant.MobileQueueConstant.QUEUE).build();
        }

        @Bean
        Exchange mobileExchange(){
            return ExchangeBuilder.directExchange(RabbitMQConstant.MobileQueueConstant.EXCHANGE).durable(true).build();
        }

        @Bean
        Binding mobileBinder(){
            return BindingBuilder.bind(mobileQueue()).to(mobileExchange()).with(RabbitMQConstant.MobileQueueConstant.ROUTING_KEY).noargs();
        }

    }



    @Configuration
    public static class MobileMessageQueueConfig{

        @Bean
        Queue mobileMessageQueue(){
            return QueueBuilder.durable(RabbitMQConstant.MobileMessageQueueConstant.QUEUE).build();
        }

        @Bean
        Exchange mobileMessageExchange(){
            return ExchangeBuilder.topicExchange(RabbitMQConstant.MobileMessageQueueConstant.EXCHANGE).durable(true).build();
        }

        @Bean
        Binding mobileMessageBinding(){
            return BindingBuilder.bind(mobileMessageQueue()).to(mobileMessageExchange()).with(RabbitMQConstant.MobileMessageQueueConstant.ROUTING_KEY).noargs();
        }

    }
}
